import requests

headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer xai-SZbJ1rR0DrPYLiyywk4mMx7p3WHZ6gnpnEakYrInYX9lhsEX0A4ARd7AlVsvxSjYUoFQfjVMOCGUldYc",
}

json_data = {
    "messages": [
        {
            "role": "system",
            "content": "你是P图大师",
        },
        {
            "role": "user",
            "content": "给我生成一个一只穿着太空服的橘猫在月球表面探索，背景是浩瀚的星空和蓝色的地球图片",
        },
    ],
    "model": "grok-4-latest",
    "stream": False,
    "temperature": 0,
}


# 发送POST请求
response = requests.post("https://api.x.ai/v1/chat/completions", headers=headers, json=json_data)

# 检查响应
if response.status_code == 200:  # 成功
    result = response.json()  # 解析JSON
    print(result)
    print("AI Response:", result["choices"][0]["message"]["content"])  # 提取AI回复内容
    print("Full Result:", result)  # 打印完整结果
else:
    print("Error:", response.status_code, response.text)  # 错误处理
